package com.easybuilder.blog.controller;

import com.alibaba.fastjson.JSONObject;
import com.easybuilder.blog.dto.ArticleCommentDTO;
import com.easybuilder.blog.dto.BlogCommentDTO;
import com.easybuilder.blog.entity.BlogArticleComment;
import com.easybuilder.blog.entity.BlogComment;
import com.easybuilder.blog.service.CommentService;
import com.easybuilder.common.base.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@Slf4j
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    /***
     * @Author zhangxingshuai
     * @Description //TODO 评论文章
     * @Date 15:25 2022/1/24
     **/
    @PostMapping("/publish")
    public Object articleComment(@RequestBody BlogComment blogComment){
        log.info("文章评论传参：{}", JSONObject.toJSONString(blogComment));
        // 插入评论数据
        BlogComment comment = commentService.articleComment(blogComment);
        return OK(comment);
    }

    @GetMapping("/list/{worksType}/{worksId}")
    public Object getCommentByArticle(@PathVariable(name = "worksType", required = true) Integer worksType,@PathVariable(name = "worksId", required = true) Long worksId) {
        log.info("根据文章id获取评论列表，传参：作品类型：{}，作品id：{}", worksType, worksId);
        List<BlogCommentDTO> list = commentService.getCommentByArticle(worksType, worksId);
        return OK(list);
    }


}
